<?php
namespace app\admin\model;

use think\Model;

class Archive extends Model
{
	protected $autoWriteTimestamp	= true;
	protected $updateTime			= false;
	protected $insert				= ['user_id'];


	public function category()
	{
		//用法：belongsTo('关联模型','外键','关联表主键');
		return $this->belongsTo('Category');
	}

	public function article()
	{
		return $this->hasOne('Article','archive_id');
	}

	public function product()
	{
		return $this->hasOne('Product');
	}




	public function deleteArchive($id)
	{
		/**
		 * [$archiveRow 删除文档]
		 * @var [type]
		 */
		$archiveRow = self::get($id);

		if($archiveRow == false)
		{
			$this->error = "this archive [id:". $id ."] do not exist";

			return false;
		}

		//删除attach的文档

		//删除附属的图片
		//Strings::deleteFile($aricleRow->thumbnail);

		return $archiveRow->delete();
	}

	//模型自动设置
	protected function setUserIdAttr()
	{
		return 10001;
	}
}